<template>
    <a-card :bordered="false">
        <div class="table-page-search-wrapper">
            <h2 class="text-center  margin-bottom" v-if="queryParam.recycleState == '2'">
                超过2天未收运预警
            </h2>
            <h2 class="text-center  margin-bottom" v-else>
                6~8小时内即将超时未收运预警
            </h2>
            <a-form layout="inline" @keyup.enter.native="searchQuery">
                <a-row :gutter="24">
                    <a-col :md="6" :sm="24">
                        <a-form-item label="产生单位">
                            <a-input v-model="queryParam.customerName" placeholder="请选择机构名称"/>
                        </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="24">
                        <a-form-item label="预警类型">
                            <a-select placeholder="预警类型" v-model="queryParam.recycleState">
                                <a-select-option value="1">6~8小时内即将超时未收运预警</a-select-option>
                                <a-select-option value="2">超过2天未收运预警</a-select-option>
                            </a-select>
                        </a-form-item>
                    </a-col>
                    <a-col :md="6" :sm="24" v-has="'query:company:select:auth'">
                        <a-form-item label="处置单位">
                            <select-company-list @change="changeCompany"></select-company-list>
                        </a-form-item>
                    </a-col>
                    <a-col :md="8" :sm="24" v-if="showSelectArea">
                        <a-form-item label="区域查询">
                            <select-area ref="selectAreaRef" @change="changeArea"></select-area>
                        </a-form-item>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <!-- 查询区域-END -->
        <div class="table-operator" style="display: flex;justify-content: space-between;align-items: center;">
            <div>
                <a-button type="primary" @click="searchQuery" icon="search">查询数据列表</a-button>
                <a-button type="primary" @click="resetForm">重置查询</a-button>
            </div>
            <div>
                <a-button type="primary" icon="printer" v-print="'#printTableList'">打印</a-button>
                <!--<a-button type="primary" icon="download" @click="handleMwExportXlsForImages">-->
                <!--导出Excel-->
                <!--</a-button>-->
            </div>
        </div>

        <!-- table区域-begin -->
        <div>
            <a-table
                    ref="table"
                    size="middle"
                    bordered
                    rowKey="id"
                    :columns="columns"
                    :dataSource="dataSource"
                    :pagination="ipagination"
                    :loading="loading"
                    class="j-table-force-nowrap"
                    @change="handleTableChange"
            >
                <template slot="htmlSlot" slot-scope="text">
                    <div v-html="text"></div>
                </template>
                <template slot="link" slot-scope="text,record">
                    <a href="#" style="color: #3fe4f1;" @click="handleShowDetail(record)">{{text}}</a>
                </template>
                <template slot="imgSlot" slot-scope="text">
                    <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
                    <img v-else :src="text" height="25px" alt style="width: auto;height: 50px;"/>
                </template>
            </a-table>
        </div>

        <div v-show="false">
            <div id="printTableList">
                <h2 class="text-center " v-if="queryParam.recycleState == '2'">
                    超过2天未收运预警名单
                </h2>
                <h2 class="text-center " v-else>
                    6~8小时内即将超时未收运预警名单
                </h2>
                <h3>打印时间 ： {{new Date().FormatDate()}}</h3>
                <a-table
                        size="small"
                        bordered
                        rowKey="id"
                        :columns="printColumns"
                        :dataSource="dataSource"
                        :pagination="false"
                >
                    <template slot="htmlSlot" slot-scope="text">
                        <div style="color: black !important;" v-html="text"></div>
                    </template>
                </a-table>
            </div>
        </div>

    </a-card>
</template>

<script>
    /**
     * create by Yang
     * 超过两天未收运预警
     * 6~8小时内即将超时未收运预警
     */
    import { mixinDevice } from '@/utils/mixin'
    import { JeecgListMixin } from '@/mixins/JeecgListMixin'
    import SelectArea from '@/components/Jane/SelectArea'
    import SelectCompanyList from '@/components/Jane/SelectCompanyList'

    export default {
        mixins: [JeecgListMixin, mixinDevice],
        components: {
            SelectArea,
            SelectCompanyList
        },
        data() {
            return {
                title: '收运超时预警',
                // 表头
                columns: [
                    {
                        title: '序号',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        customRender: function(t, r, index) {
                            return parseInt(index) + 1
                        }
                    },
                    {
                        title: '机构名称',
                        align: 'center',
                        dataIndex: 'customerName'
                    },
                    {
                        title: '提交时间',
                        align: 'center',
                        dataIndex: 'createTime'
                    },
                    {
                        title: '超时未收运时间',
                        align: 'center',
                        dataIndex: 'remark',
                        scopedSlots: { customRender: 'htmlSlot' },
                        customRender: function(value, row, index) {
                            const obj = {
                                children: < span
                            style = 'color:orange;' > { value } < /span>,
                            attrs: {
                            }
                        }
                            return obj
                        }
                    },
                    {
                        title: '机构地址',
                        align: 'center',
                        dataIndex: 'customerAddress',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    }
                ],
                printColumns: [
                    {
                        title: '序号',
                        dataIndex: '',
                        key: 'rowIndex',
                        width: 60,
                        align: 'center',
                        customRender: function(t, r, index) {
                            return parseInt(index) + 1
                        }
                    },
                    {
                        title: '机构名称',
                        align: 'center',
                        dataIndex: 'customerName'
                    },
                    {
                        title: '提交时间',
                        align: 'center',
                        dataIndex: 'createTime',
                    },
                    {
                        title: '超时未收运时间',
                        align: 'center',
                        dataIndex: 'remark',
                        scopedSlots: { customRender: 'htmlSlot' },
                        customRender: function(value, row, index) {
                            const obj = {
                                children: < span
                            style = 'color:orange;' > { value } < /span>,
                            attrs: {
                            }
                        }
                            return obj
                        }
                    },

                    {
                        title: '机构地址',
                        align: 'center',
                        dataIndex: 'customerAddress',
                        customRender: function(value, row, index) {
                            return value || ' '
                        }
                    }
                ],
                url: {
                    list: '/hc/hcRecycleBagcode/timeoutBySixAndEight',   // 小董接口 3.0 : 查询数据列表
                },
                dictOptions: {},
                queryParam: {
                    // 1 6~8小时内即将到期未收运预警   2 超过2天未收运预警名单
                    recycleState: 1,
                    customerName: '',
                    cityCode: '',
                    areaCode: '',
                    companysId: ''

                }
            }
        },
        created() {
             this.initData()

        },
        computed: {
            showSelectArea: function() {
                let state = true
                let userInfo = this.$store.getters.userInfo
                if (userInfo.provinceCode && userInfo.cityCode && userInfo.areaCode) {
                    state = false
                }
                return state
            }
        },
        methods: {
            // 初始化数据
            initData: function() {
                for (let i in this.queryParam) {
                    this.queryParam[i] = ''
                }
                // 获取到用户登陆的信息
                let userInfo = this.$store.getters.userInfo
                // 如果用户存在区县编码、处置单位Id编号，则赋值
                if (userInfo.cityCode) {
                    this.queryParam.cityCode = userInfo.cityCode
                }
                if (userInfo.areaCode) {
                    this.queryParam.areaCode = userInfo.areaCode
                }
                if (userInfo.companysId) {
                    this.queryParam.companysId = userInfo.companysId;
                }
                let ref = this.$refs.selectAreaRef
                if (ref && ref.clearSelectArea != undefined) {
                    ref.clearSelectArea()
                }
            },
            async changeArea({ area, city }) {
                if (city) {
                    this.queryParam.cityCode = city
                }
                if (area) {
                    this.queryParam.areaCode = area
                }
            },
            async changeCompany(value, option) {
                this.queryParam.companysId = value
            },
            searchQuery: function() {
                this.loadData(1)
            },
            resetForm: function() {
                this.initData()
                this.searchQuery()
            }


        }
    }
</script>

<style scoped>
</style>
